using System.Collections;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Ezio.Model;

//Service Route: Copy to 'Global.asax'
//  RouteTable.Routes.Add(new ServiceRoute("Menus", new WebServiceHostFactory(), typeof(MenusService)));
//
namespace Ezio.Service
{
    [ServiceContract]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    [XmlSerializerFormat]
    public class MenusService : BaseService
    {

        [WebInvoke(UriTemplate = "", Method = "POST")]
        public bool Create(Menus Menu)
        {
            Provider.AddToMenus(Menu);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "", Method = "GET")]
        public ArrayList GetAll()
        {
            return new ArrayList(Provider.Menus.ToList());
        }

        [WebInvoke(UriTemplate = "{Id}", Method = "GET")]
        public Menus GetById(string Id)
        {
            return Provider.Menus.First(i => i.IdMenu == int.Parse(Id));
        }

        [WebInvoke(UriTemplate = "", Method = "PUT")]
        public bool Update(Menus Menu)
        {
            Menus miMenu = Provider.Menus.Where(t => t.IdMenu == Menu.IdMenu).First();
            miMenu.Copy(Menu);
            return Provider.TrySaveChanges();
        }

        [WebInvoke(UriTemplate = "{IdMenu}", Method = "DELETE")]
        public bool Delete(string IdMenu)
        {
            int Id = int.Parse(IdMenu);
            Provider.Menus.DeleteObject(Provider.Menus.Where(t => t.IdMenu == Id).First());
            return Provider.TrySaveChanges();
        }

    }
}